<?php
/*点击模块的打点操作
  参数：
  	$model：   用户点击的模块名称
*/
function dadian($model){
      /*****打点统计开始*****/
                $uid=cookie("uid");
                // $uid="wanggang";
                $url = "http://localhost" . U("Serviceapi/getUserInfo"); 
                $data=array(
                  'uid'=>$uid,
                  ); 
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             $return = curl_exec($ch);
             curl_close($ch);
             $return =json_decode($return);
             $return=$return->data;
             $mobile=$return->userPreferredMobile;
             // var_dump($phone);exit();



                $url = "http://localhost" . U("Serviceapi/addOperationStatisticsData");  
                $operateDetail=$uid."于".date("Y-m-d h:i:s")."通过ip:".$_SERVER["REMOTE_ADDR"]."点击体检预约模块成功";
                //组织参数datas
                $datas=array(
                    'items'=>array(
                       'operateTime'=>date("Y-m-d H:i:s"),
                       'beginTime'=>date("Y-m-d H:i:s"),
                       'endTime'=>date("Y-m-d H:i:s"),
                       'useruid'=>$uid,
                       'operateTypeDict'=>7,
                       'eventTypeDict'=>30,
                       'operateChannelDict'=>5,     //通过html5提交
                       'operateObjectDict'=>"",
                       'mobile'=>$mobile,
                       'operateObjectName'=>"体检服务/体检通/".$model,
                       'operateIp'=>$_SERVER["REMOTE_ADDR"],
                       'value'=>1,
                       'operateDetail'=>$operateDetail,
                       )

                    );
                foreach ($datas['items'] as $key => $value) {
                 $datas['items'][$key]=urlencode($value);
             }
             $datas =  urldecode(json_encode($datas));
             // var_dump($datas);exit();
             $data = array(
                'datas' =>$datas,
                );
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             $return = curl_exec($ch);
             // var_dump($return);exit();
             curl_close($ch);
            
            //如果打点统计失败，给管理员发短信-开始
             if($return==="1"){
                $content_dadian =  $uid . "先生/女士在和健康".$model."，打点失败，请管理员处理！";
                $url = "http://localhost" . U("Serviceapi/sendShortMessageByPhoneNumber");
                $data = array(
                    'phoneNumbers' => 18301682292,                 //给管理员李志辉发短信
                    'content' => $content_dadian,
                    'pageSize' => '10000',
                    'sendTime' => date("Y-m-d G:i:s"),
                    );

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);
                $messgInfo = get_object_vars(json_decode($return));
                return false;
             }else{
                 return true;
             }

            

}
